package com.springlearn.springsourcecode.chap13;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author wtcode
 * @Description
 * @date 2025/4/2 - 9:35
 */
public class A13 {

    interface Foo {
        void foo();
        int bar();
    }

    static class Target implements Foo{
        @Override
        public void foo() {
            System.out.println("foo method");
        }

        @Override
        public int bar() {
            System.out.println("bar method");
            return 100;
        }
    }


    /*interface InvocationHandler{
        Object invoke(Object proxy, Method method, Object[] args) throws Throwable;
    }*/

    public static void main(String[] args) {
        $Proxy0 proxy = new $Proxy0(new InvocationHandler() {
            @Override
            public Object invoke(Object object, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
                System.out.println("before");
                return method.invoke(new A13.Target(),args);
            }
        });
        proxy.foo();
        proxy.bar();
    }
}
